import BaseResult from '../lib/BaseResult.js'

var redis = require("redis");
var client = redis.createClient();

client.on("error", function(err) {
    console.log("Error " + err);
});
class Sign {
    // static async set(ctx) {
    //     let data = ctx.query;
    //     console.log(data)
    //     let sign =  new Buffer(data.sign,'base64');
    //     ctx.session[data.token] = JSON.parse(sign.toString());
    //     ctx.body = new BaseResult(0,null ,null);
    // }
    static async get(ctx, next) {
        //   let token = ctx.request.body.token||ctx.query.token||ctx.request.header.token;
        return new Promise((resolve) => {
            if (!ctx.token) {
                ctx.body = new BaseResult(9999, null, null);
                resolve();
            }
            client.get(ctx.token, function(err, res) {
                console.log(res);
                if (res) {
                    ctx.body = new BaseResult(0, null, res);
                } else {
                    ctx.body = new BaseResult(9999, 'token无效', null);
                }
                resolve();
            })
        })

        // if (ctx.session[ctx.token]) {
        //     ctx.body = new BaseResult(0, null, ctx.session[ctx.token]);
        //     return false;
        // }
        // ctx.body = new BaseResult(9999, 'token无效', null);
    }
}
export default Sign;